import { eventHandler } from 'h3';
import { verifyAccessToken } from '~/utils/jwt-utils';
import { MOCK_MENUS } from '~/utils/mock-data';
import {
  unAuthorizedResponse,
  useResponseError,
  useResponseSuccess,
} from '~/utils/response';

export default eventHandler(async (event) => {
  try {
    const userinfo = verifyAccessToken(event);
    if (!userinfo) {
      return unAuthorizedResponse(event);
    }

    const menus =
      MOCK_MENUS.find((item) => item.username === userinfo.username)?.menus ??
      [];
    return useResponseSuccess(menus);
  } catch (error) {
    console.error('Menu API error:', error);
    return useResponseError('InternalServerError', 'Failed to get menu data');
  }
});
